﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessObjects.BO_GetObjects;

public partial class Pages_SignIn : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["reference"] = Request.UrlReferrer.AbsoluteUri;
            LoadSidebarModule();
        }
    }

    protected void Regist(object sender, EventArgs e)
    {
        DataTable objDT = BO_Members.Login(txtUsername.Value, txtPassword.Value);
        if (objDT.Rows.Count > 0)
        {
            if (objDT.Rows[0][0].ToString() != "0")
            {
                Response.Redirect(Session["reference"].ToString(), false);
            }
            else
            {
                Response.Write("not ok");
            }
        }
        else
        {
            Response.Write("not ok");
        }
    }

    protected void LoadSidebarModule()
    {
        DataTable objDT = null;
        objDT = BO_Module.SelectLocation(3);
        for (int i = 0; i < objDT.Rows.Count; i++)
        {
            if (objDT.Rows[i]["type_id"].ToString() == "3")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucCustomSearch.ascx");
                Controls_ucCustomSearch control = (Controls_ucCustomSearch)controls;
                plHolderSidebar.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "4")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucRegistService.ascx");
                Controls_ucRegistService control = (Controls_ucRegistService)controls;
                plHolderSidebar.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "5")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucSupport.ascx");
                Controls_ucSupport control = (Controls_ucSupport)controls;
                plHolderSidebar.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "6")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucAds.ascx");
                Controls_ucAds control = (Controls_ucAds)controls;
                control.Module_id = objDT.Rows[i]["MODULE_ID"].ToString();
                plHolderSidebar.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "7")
            {
                //UserControl controls = (UserControl)Page.LoadControl("../controls/ucRegistService.ascx");
                //Controls_ucRegistService control = (Controls_ucRegistService)controls;
                //pldHolderLeft.Controls.Add(controls);
            }
        }
    }
}